   //
//  YWKVerificationCodeViewController.m
//  YWKUser
//
//  Created by Admin on 16/4/26.
//  Copyright © 2016年 iCareTech. All rights reserved.
//

#import "YWKVerificationCodeViewController.h"
#import "YWKSetPasswordVC.h"
#import "YWKLable.h"
#import "YWKHelper.h"
#import "UIColor+ICT.h"
#import "YWKLoginAndRegistModel.h"
#import "YWKLoginHander.h"
#import "MBProgressHUD+YWK.h"
#import "YWKConfiguration.h"
#import "FiexibleTool.h"
#import <RMUniversalAlert.h>
#import <RealReachability.h>
#import <DDLog.h>

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_INFO;
#else
static const int ddLogLevel = LOG_LEVEL_ERROR;
#endif
#define zCodeCountTime     60
#define kPhoneNumberTag    200
@interface YWKVerificationCodeViewController ()<
UITextFieldDelegate,
YWKLoginAndRegistModelDelegate,
YWKLoginHander>

@property (nonatomic, strong) UIButton * nextBtn;
//@property (nonatomic, strong) UIScrollView * scrollView;
@property (nonatomic, strong) UIView * contentOfScrollView;
@property (nonatomic, strong) UIView * containerView;
@property (nonatomic, strong) UIView * middleLineView;
@property (nonatomic, strong) YWKLable * phoneNOLab;
@property (nonatomic, strong) YWKLable * codeLab;
@property (nonatomic, strong) UITextField * phoneNOTF;
@property (nonatomic, strong) UITextField * codeTF;
@property (nonatomic, strong) UIButton * queryCodeAndTimeBtn;
@property (nonatomic, strong) UIView * maskView;
@property (nonatomic, strong) YWKLable * morethanCodeCountLab;
@property (nonatomic, strong) YWKLoginAndRegistModel *dataModel;
@property (nonatomic, strong) NSTimer * timer;
@property (nonatomic, assign) NSInteger count;
@property (nonatomic, strong) YWKLoginHander * loginHander;
@property (nonatomic, strong) MBProgressHUD * HUD;
@property (nonatomic, copy) NSString * phoneNumber;

@end

@implementation YWKVerificationCodeViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = NSLocalizedString(@"使用验证码登录", nil);
    
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
    //导航返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                             initWithImage:[UIImage imageNamed:@"nav_backArrow"]
                                             style:UIBarButtonItemStylePlain
                                             target:self
                                             action:@selector(popVC)];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:[FiexibleTool floatWithOriginalFloat:16.f
                                                                        isFlexibleHeight:YES]],
       NSForegroundColorAttributeName:[UIColor blackColor]}];
    [self.view addSubview:self.contentOfScrollView];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    // Constraint
//    // scroll
//    [YWKHelper addConstraintInFirstItem:self.scrollView
//                           toSecondItem:self.view
//                               topSpace:0 leftSpace:0 rightSpace:0 bottomSpace:0 superView:nil];
    [YWKHelper addConstraintInFirstItem:self.contentOfScrollView
                           toSecondItem:self.view
                               topSpace:0 leftSpace:0 rightSpace:0 bottomSpace:0 superView:nil];
    
    [YWKHelper onlyAddVerticalCentreXConstraintInFirstItem:self.contentOfScrollView
                                              toSecondItem:self.view];
    [YWKHelper onlyAddVerticalCentreYConstraintInFirstItem:self.contentOfScrollView
                                              toSecondItem:self.view];
    
    [YWKHelper addConstraintInFirstItem:self.containerView
                           toSecondItem:self.contentOfScrollView
                               topSpace:20 leftSpace:10 rightSpace:-10 height:85 superView:nil];
    
    // lab
    [YWKHelper addConstraintInFirstItem:self.phoneNOLab
                           toSecondItem:self.containerView
                               topSpace:0 leftSpace:20 bottomSpace:-(42 + 1) width:60 superView:nil];
    [YWKHelper addConstraintInFirstItem:self.codeLab
                           toSecondItem:self.containerView
                               topSpace:42 + 1 leftSpace:20 bottomSpace:0 width:60 superView:nil];
    
    // textfield
    [YWKHelper addConstraintInFirstItem:self.phoneNOTF
                           toSecondItem:self.containerView
                               topSpace:0
                              leftSpace:30 + 60 + 5
                             rightSpace:0
                            bottomSpace:-(42 + 1)
                              superView:nil];
    
    [YWKHelper addConstraintInFirstItem:self.codeTF
                           toSecondItem:self.containerView
                               topSpace:42 + 1
                              leftSpace:30 + 60 + 5
                             rightSpace:-80
                            bottomSpace:0
                              superView:nil];
    
    // code
    [YWKHelper addConstraintInFirstItem:self.queryCodeAndTimeBtn
                           toSecondItem:self.containerView
                               topSpace:42 + 1
                             rightSpace:-10
                            bottomSpace:0
                                  width:80
                              superView:nil];
    
    [YWKHelper addVerticalCentreYConstraintInFirstItem:self.middleLineView
                                          toSecondItem:self.containerView
                                             leftSpace:0
                                            rightSpace:0
                                                height:1
                                             superView:nil];

    // button
    [YWKHelper addConstraintInFirstItem:self.nextBtn
                           toSecondItem:self.containerView
                            bottomSpace:20
                              leftSpace:10
                             rightSpace:-10
                                 height:40
                              superView:self.contentOfScrollView];
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillShow:)
//                                                 name:UIKeyboardWillShowNotification
//                                               object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillHide:)
//                                                 name:UIKeyboardWillHideNotification
//                                               object:nil];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
//    [[NSNotificationCenter defaultCenter] removeObserver:self
//                                                    name:UIKeyboardWillShowNotification
//                                                  object:nil];
//    [[NSNotificationCenter defaultCenter] removeObserver:self
//                                                    name:UIKeyboardWillHideNotification
//                                                  object:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [_timer invalidate];
}


#pragma mark -UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
    if ([string isEqualToString:@"\n"]) {
        
        [textField resignFirstResponder];
        return NO;
    }
    
    if (textField == self.phoneNOTF)
    {
        if (string.length > 0)
        {
            if ((textField.text.length == 3)||(textField.text.length == 8))
            {
                textField.text = [NSString stringWithFormat:@"%@ ", textField.text];
                
            }else if(textField.text.length == 13){
                
                [self.view endEditing:YES];
            }
        }
    }
    return YES;
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == self.phoneNOTF) {
        
        [self.codeTF becomeFirstResponder];
    }
}



#pragma mark - keyboard notifation
//- (void)keyboardWillShow:(NSNotification *)keyboardWillShowNotifi
//{
//    NSDictionary * keyboardInfo = keyboardWillShowNotifi.userInfo;
//    CGSize keyboardSize = [[keyboardInfo objectForKey:UIKeyboardFrameBeginUserInfoKey]
//                           CGRectValue].size;
//    CGFloat offsetY = [self calculateOffsetYWithkeyboardSize:keyboardSize];
//    [self.scrollView setContentOffset:CGPointMake(0, offsetY) animated:YES];
//}
//
//- (void)keyboardWillHide:(NSNotification *)keyboardWillHideNotifi
//{
//
//    [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
//}

#pragma mark -YWKLoginAndRegistDelegate

/**
 *  手机号或者账号是否存在
 *
 */
- (void)checkUserNameHasexisted:(NSDictionary *)response{
    
    NSInteger result = [response[@"result"] integerValue];
    NSString *sendString;
    
    if (result == 20) {
        
        sendString = NSLocalizedString(@"手机验证码已发送请查看手机短信", nil);
        //倒计时开始
        [self.timer setFireDate:[NSDate date]];
        [self.dataModel requestVerificationCodeAPIWithName:self.phoneNumber];
    }
    else if (result == 0)
    {
        [self.HUD removeFromSuperview];
        sendString = NSLocalizedString(@"该手机号未注册!", nil);
        self.queryCodeAndTimeBtn.userInteractionEnabled = YES;
    }
    [self showIdentifCodeWithString:sendString];
}

/**
 *  返回验证码
 *
 */
-(void)getVerificationCode:(NSString *)code{
    
    self.codeTF.text = code;
    [self.HUD removeFromSuperview];
    [self.HUD hide:YES];
}

-(void)failedWithResponse:(id)response{
    
    [self showIdentifCodeWithString:response[@"errorReason"]];
    [self.HUD removeFromSuperview];
    self.queryCodeAndTimeBtn.userInteractionEnabled = YES;
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}

#pragma mark -YWKLoginHander
- (void)loginSuccessForAccount:(YWKUser *)account{
    //登录成功后跳转。
    self.HUD.mode = MBProgressHUDModeCustomView;
    self.HUD.labelText = @"登录成功";
    UIImage *image = [UIImage imageNamed:@"checkout_white"];
    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    imageview.image = image;
    self.HUD.customView = imageview;
    self.HUD.labelFont = [UIFont fontWithName:kTextFontName
                                         size:[FiexibleTool floatWithOriginalFloat:14.f
                                                                  isFlexibleHeight:YES]];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6f * NSEC_PER_SEC)),
                   dispatch_get_main_queue(), ^{
        
        YWKSetPasswordVC * setPasswordVC = [[YWKSetPasswordVC alloc] init];
        setPasswordVC.verificationCode = self.codeTF.text;
        setPasswordVC.phoneNumber = self.phoneNOTF.text;
        /**
         *  返回
         */
        [self.HUD removeFromSuperview];
        self.nextBtn.userInteractionEnabled = YES;
        [self.navigationController pushViewController:setPasswordVC animated:YES];
    });
}

- (void)loginFailedForAccount:(YWKUser *)account withError:(NSError *)error{
    
    [self.HUD removeFromSuperview];
    DDLogInfo(@"loginFailedForAccount error = %@", [error localizedDescription]);
    [self showIdentifCodeWithString:error.userInfo[@"description"]];
    self.nextBtn.userInteractionEnabled = YES;
}

//#pragma mark - function
//- (CGFloat)calculateOffsetYWithkeyboardSize:(CGSize)keyboardSize
//{
//    CGFloat offsetY = 0.0;
//    if (self.phoneNOTF.isFirstResponder) {
//        
//        offsetY = 20 + 42 * 1 + keyboardSize.height - self.contentOfScrollView.frame.size.height;
//        if (offsetY < 0) {
//            offsetY = 0.0;
//        }
//    }
//    else if (self.codeTF.isFirstResponder)
//    {
//        offsetY = 20 + 42 * 2 + keyboardSize.height - self.contentOfScrollView.frame.size.height;
//        if (offsetY < 0) {
//            offsetY = 0.0;
//        }
//    }
//    return offsetY;
//}


/**
 *  alertView显示，3秒退出。
 *
 */
- (void)showIdentifCodeWithString:(NSString *)alertString
{
    [MBProgressHUD hubWithTitle:alertString second:3.f toView:self.view];
    self.nextBtn.userInteractionEnabled = YES;
}


- (void)popVC{
    
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

#pragma mark - btnClick

- (void)nextBtnClick:(UIButton *)sender
{
    [self.view endEditing:YES];
    RealReachability * real = [RealReachability sharedInstance];
    
    if(real.currentReachabilityStatus == RealStatusUnknown ||
       real.currentReachabilityStatus == RealStatusNotReachable)
    {
        [MBProgressHUD hubWithTitle:NSLocalizedString(@"网络不给力，稍后再试试", nil)
                             second:3
                             toView:self.view];
        return;
    }

    self.phoneNumber = [self.phoneNOTF.text stringByReplacingOccurrencesOfString:@" "
                                                                      withString:@""];
    if ([self.phoneNumber isEqualToString:@""]) {
        
        [self showIdentifCodeWithString:NSLocalizedString(@"请输入手机号!", nil)];
        return;
    }
    else if(![YWKHelper isValidatePhoneNmuber:self.phoneNumber])
    {
        [self showIdentifCodeWithString:NSLocalizedString(@"请输入正确的手机号!", nil)];
        return;
    }
    else if (![self isPureInt:self.codeTF.text] || self.codeTF.text.length != 6){
        
        [self showIdentifCodeWithString:NSLocalizedString(@"请输入6位验证码!", nil)];
        return;
    }
    else
    {
//        适应新接口
        /*
        YWKSetPasswordVC * setPasswordVC = [[YWKSetPasswordVC alloc] init];
        setPasswordVC.verificationCode = self.codeTF.text;
        setPasswordVC.phoneNumber = self.phoneNumber;
        [self.navigationController pushViewController:setPasswordVC animated:YES];
         */
        /*
        self.HUD = [MBProgressHUD YWKProgressLoadingInView:self.containerView];
        [self.view addSubview:self.HUD];
        [self.HUD show:YES];
         */
        self.HUD = [[MBProgressHUD alloc]initWithView:self.view];
        self.HUD.activityIndicatorColor = kYWKButtonBlueColor;
        self.HUD.labelText = NSLocalizedString(@"正在登录", nil);
        [self.view addSubview:self.HUD];
        [self.HUD show:YES];
        
        //初始化登录
        YWKUser *loginUser = [[YWKUser alloc] initWithLoginName:self.phoneNumber];
        self.loginHander = [YWKLoginHander loginHandler];
        [self.loginHander loginHandlerForAccount:loginUser withDelegate:self error:nil  ];
        loginUser.phoneNumber = self.phoneNumber;
        [self.loginHander startLoginWithCaptcha:self.codeTF.text withError:nil];
    }
}

//判断是否为整形：
- (BOOL)isPureInt:(NSString*)string{
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

#pragma mark --获取验证码

- (void)queryCodeAndTimeBtnClick:(UIButton *)sender
{
    RealReachability * real = [RealReachability sharedInstance];
    
    if(real.currentReachabilityStatus == RealStatusUnknown ||
       real.currentReachabilityStatus == RealStatusNotReachable)
    {
        [MBProgressHUD hubWithTitle:NSLocalizedString(@"网络不给力，稍后再试试", nil)
                             second:3
                             toView:self.view];
        return;
    }

    [self.view endEditing:YES];
    self.phoneNumber = [self.phoneNOTF.text stringByReplacingOccurrencesOfString:@" "
                                                                      withString:@""];
    if ([self.phoneNumber isEqualToString:@""]) {
        
        [self showIdentifCodeWithString:NSLocalizedString(@"请输入手机号!", nil)];
        self.queryCodeAndTimeBtn.userInteractionEnabled = YES;
    }
    else if(![YWKHelper isValidatePhoneNmuber:self.phoneNumber])
    {
        [self showIdentifCodeWithString:NSLocalizedString(@"请输入正确的手机号！", nil)];
        self.queryCodeAndTimeBtn.userInteractionEnabled = YES;
        return;
    }
    else
    {
        //判断手机号
        self.HUD = [MBProgressHUD YWKProgressLoadingInView:self.containerView];
        [self.view addSubview:self.HUD];
        [self.HUD show:YES];
        [self.dataModel fetchDataWithTelephone:self.phoneNumber];
    }
}

#pragma mark - timer

- (void)queryCodeCountTime
{
    self.queryCodeAndTimeBtn.userInteractionEnabled = NO;
    self.queryCodeAndTimeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.queryCodeAndTimeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
    NSString * str = [NSString stringWithFormat:NSLocalizedString(@"%dS", nil),
                      (zCodeCountTime - self.count)];
    self.queryCodeAndTimeBtn.titleLabel.text = str;
    [self.queryCodeAndTimeBtn setTitle:str forState:UIControlStateNormal];
    if (self.count >= zCodeCountTime)
    {
        [self.timer setFireDate:[NSDate distantFuture]];
        [self.queryCodeAndTimeBtn setTitle:NSLocalizedString(@"重新获取", nil)
                                  forState:UIControlStateNormal];
        self.queryCodeAndTimeBtn.userInteractionEnabled = YES;
        self.queryCodeAndTimeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        self.queryCodeAndTimeBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        self.count = 0;
    }
    else
    {
        self.count++;
    }
}

#pragma mark - getter

- (UIView *)contentOfScrollView
{
    if (!_contentOfScrollView) {
        
        _contentOfScrollView = [[UIView alloc] initWithFrame:CGRectZero];
        _contentOfScrollView.translatesAutoresizingMaskIntoConstraints = NO;
        _contentOfScrollView.backgroundColor = [UIColor clearColor];
        [_contentOfScrollView addSubview:self.containerView];
        [_contentOfScrollView addSubview:self.nextBtn];
    }
    return _contentOfScrollView;
}

- (UIButton *)nextBtn
{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _nextBtn.translatesAutoresizingMaskIntoConstraints = NO;
        _nextBtn.layer.cornerRadius = 10;
        _nextBtn.layer.borderWidth = 1;
        _nextBtn.layer.borderColor = [UIColor colorWithHex:0x009FE9].CGColor;
        _nextBtn.layer.masksToBounds = YES;
        [_nextBtn setTitleColor:[UIColor colorWithHex:0x009FE9] forState:UIControlStateNormal];
        [_nextBtn setTitle:NSLocalizedString(@"下一步", nil) forState:UIControlStateNormal];
        [_nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}

- (UIView *)containerView
{
    if (!_containerView) {
        _containerView = [[UIView alloc] initWithFrame:CGRectZero];
        _containerView.layer.cornerRadius = 15;
        _containerView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _containerView.layer.borderWidth = 1;
        _containerView.layer.masksToBounds = YES;
        _containerView.translatesAutoresizingMaskIntoConstraints = NO;
        
        [_containerView addSubview:self.middleLineView];
        [_containerView addSubview:self.phoneNOLab];
        [_containerView addSubview:self.codeLab];
        [_containerView addSubview:self.phoneNOTF];
        [_containerView addSubview:self.codeTF];
        [_containerView addSubview:self.queryCodeAndTimeBtn];
    }
    return _containerView;
}

- (UIView *)middleLineView
{
    if (!_middleLineView) {
        _middleLineView = [[UIView alloc] initWithFrame:CGRectZero];
        _middleLineView.backgroundColor = [UIColor lightGrayColor];
        _middleLineView.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _middleLineView;
}

- (YWKLable *)phoneNOLab
{
    if (!_phoneNOLab) {
        
        _phoneNOLab = [[YWKLable alloc] initWithFrame:CGRectZero];
        _phoneNOLab.text = NSLocalizedString(@"手机号码", nil);
        _phoneNOLab.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _phoneNOLab;
}

- (YWKLable *)codeLab
{
    if (!_codeLab) {
        
        _codeLab = [[YWKLable alloc] initWithFrame:CGRectZero];
        _codeLab.text = NSLocalizedString(@"验证码", nil);
        _codeLab.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _codeLab;
}

- (UITextField *)phoneNOTF
{
    if (!_phoneNOTF) {
        
        _phoneNOTF = [[UITextField alloc] initWithFrame:CGRectZero];
        _phoneNOTF.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        _phoneNOTF.placeholder = NSLocalizedString(@"请输入手机号码", nil);
        _phoneNOTF.delegate = self;
        _phoneNOTF.keyboardType = UIKeyboardTypeNumberPad;
        _phoneNOTF.returnKeyType = UIReturnKeyNext;
        _phoneNOTF.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _phoneNOTF;
}

- (UITextField *)codeTF
{
    if (!_codeTF) {
        
        _codeTF = [[UITextField alloc] initWithFrame:CGRectZero];
        _codeTF.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        _codeTF.translatesAutoresizingMaskIntoConstraints = NO;
        _codeTF.delegate = self;
        _codeTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _codeTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _codeTF.returnKeyType = UIRectEdgeNone;
    }
    return _codeTF;
}

- (UIButton *)queryCodeAndTimeBtn
{
    if (!_queryCodeAndTimeBtn) {
        
        _queryCodeAndTimeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _queryCodeAndTimeBtn.translatesAutoresizingMaskIntoConstraints = NO;
        _queryCodeAndTimeBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [_queryCodeAndTimeBtn setTitleColor:[UIColor colorWithHex:0x009FE9]
                                   forState:UIControlStateNormal];
        [_queryCodeAndTimeBtn setTitle:NSLocalizedString(@"获取验证码", nil)
                              forState:UIControlStateNormal];
        [_queryCodeAndTimeBtn addTarget:self
                                 action:@selector(queryCodeAndTimeBtnClick:)
                       forControlEvents:UIControlEventTouchUpInside];
    }
    return _queryCodeAndTimeBtn;
}

- (UIView *)maskView
{
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:CGRectZero];
        _maskView.translatesAutoresizingMaskIntoConstraints = NO;
        _maskView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1];
        [_maskView addSubview:self.morethanCodeCountLab];
    }
    return _maskView;
}

- (YWKLable *)morethanCodeCountLab
{
    if (!_morethanCodeCountLab) {
        _morethanCodeCountLab = [[YWKLable alloc] initWithFrame:CGRectZero];
        _morethanCodeCountLab.translatesAutoresizingMaskIntoConstraints = NO;
        _morethanCodeCountLab.numberOfLines = 2;
        _morethanCodeCountLab.textAlignment = NSTextAlignmentCenter;
        _morethanCodeCountLab.text = NSLocalizedString(@"发送验证码次数超限，\n请使用帐号登录", nil);
    }
    return _morethanCodeCountLab;
}

- (NSTimer *)timer
{
    if (!_timer) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                  target:self
                                                selector:@selector(queryCodeCountTime)
                                                userInfo:nil
                                                 repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    }
    return _timer;
}

- (YWKLoginAndRegistModel *)dataModel{
    
    if (!_dataModel) {
        
        _dataModel = [[YWKLoginAndRegistModel alloc]init];
        _dataModel.loginAndRegistDelegate = self;
    }
    return _dataModel;
}

@end
